//
//  RegistView.m
//  UI-word-13_豆瓣
//
//  Created by lanou3g on 15/8/25.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "RegistView.h"

@implementation RegistView

//初始化
-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubviews];
    }
    return self;
}

- (void)addSubviews{
    //用户名
    _userLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.frame.size.width / 12 * 1, 90, self.frame.size.width / 5 + 20, 40)];
    _userLabel.text = @"用户名";
    _userLabel.font = [UIFont systemFontOfSize:20];
    [self addSubview:_userLabel];
    _userTextField = [[UITextField alloc]initWithFrame:CGRectMake(self.frame.size.width / 5 + 60, 90,self.frame.size.width / 5  * 3 - 20, 40)];
    _userTextField.placeholder = @"请输入用户名";
    _userTextField.font = [UIFont systemFontOfSize:20];
    _userTextField.tag = 201;
    _userTextField.delegate = self;
    _userTextField.borderStyle = UITextBorderStyleRoundedRect;
    [self addSubview:_userTextField];
    
    //密码
    _passwordLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.frame.size.width / 12 * 1, 160, self.frame.size.width / 5 + 20, 40)];
    _passwordLabel.text = @"密码";
    _passwordLabel.font = [UIFont systemFontOfSize:20];
    [self addSubview:_passwordLabel];
    _passwordTextField = [[UITextField alloc]initWithFrame:CGRectMake(self.frame.size.width / 5 + 60, 160,self.frame.size.width / 5  * 3 -20, 40)];
    _passwordTextField.placeholder = @"请输入密码";
    _passwordTextField.font = [UIFont systemFontOfSize:20];
    _passwordTextField.tag = 202;
    _passwordTextField.delegate = self;
    _passwordTextField.borderStyle = UITextBorderStyleRoundedRect;
    [self addSubview:_passwordTextField];
    
    //确认密码
    _countersignPasswordLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.frame.size.width / 12 * 1, 230, self.frame.size.width / 5 + 20 , 40)];
    _countersignPasswordLabel.text = @"确认密码";
    _countersignPasswordLabel.font = [UIFont systemFontOfSize:20];
    [self addSubview:_countersignPasswordLabel];
    _countersignPasswordTextField = [[UITextField alloc]initWithFrame:CGRectMake(self.frame.size.width / 5 + 60, 230, self.frame.size.width / 5  * 3 - 20, 40)];
    _countersignPasswordTextField.placeholder = @"请再次输入密码";
    _countersignPasswordTextField.font = [UIFont systemFontOfSize:20];
    _countersignPasswordTextField.tag = 203;
    _countersignPasswordTextField.delegate = self;
    _countersignPasswordTextField.borderStyle = UITextBorderStyleRoundedRect;
    [self addSubview: _countersignPasswordTextField];
    
    //按钮
    _registBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _registBtn.frame = CGRectMake(20, 300, (self.frame.size.width-60)/2, 40);
    [_registBtn setTitle:@"注册" forState:UIControlStateNormal];
    _registBtn.backgroundColor = [UIColor colorWithRed:174/255.0 green:214/255.0 blue:97/255.0 alpha:1];
    _registBtn.layer.masksToBounds = YES;
    _registBtn.layer.cornerRadius = 5.0;
    [_registBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self addSubview:_registBtn];
    
    _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _cancelBtn.frame = CGRectMake((self.frame.size.width-60)/2+40, 300, (self.frame.size.width-60)/2, 40);
    [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    _cancelBtn.backgroundColor = [UIColor colorWithRed:230/255.0 green:136/255.0 blue:56/255.0 alpha:1];
    _cancelBtn.layer.masksToBounds = YES;
    _cancelBtn.layer.cornerRadius = 5.0;
    [_cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self addSubview:_cancelBtn];
    
}



//让下一个textField成为第一响应者
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    NSInteger tag = textField.tag;
    if (tag != 205) {
        [[self viewWithTag:tag+1] becomeFirstResponder];
        return YES;
    } else {
        [textField resignFirstResponder];
        return YES;
    }
}

//点击空白处回收键盘
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self endEditing:YES];
}



@end
